const db = uniCloud.database()

export function getTypeList() {
	return db.collection('project-type').get()
}

export function getUsers({
	pageNum,
	pageSize,
	school
}) {
	return db.collection('uni-id-users').where({
		school
	}).skip((pageNum - 1) * pageSize).limit(pageSize).get({
		getCount: true
	})
}

export async function getProject({
	pageNum,
	pageSize,
	type
}) {
	let result = await db.collection('project-activity').get()
	let arr = result.result.data.map((item) => {
		db.collection('uni-id-users').where({
			'_id': item.author
		}).get().then((res) => {
			console.log(res.result)
			let username = res.result.data[0].username || ""
			item.author = username
		})
		return item
	})
	return arr
}

export function getSignNum({
	activityId,
	user_id
}) {
	return db.collection('project-signin').where({
		activity_id: activityId,
		user_id
	}).get({
		getCount: true
	})
}
